// 校验正则
import { REGEXP } from './constants'

// 验证手机号
export function validatePhone(phone: string): boolean {
  return REGEXP.PHONE.test(phone)
}

// 验证邮箱
export function validateEmail(email: string): boolean {
  return REGEXP.EMAIL.test(email)
}

// 验证密码
export function validatePassword(password: string): boolean {
  return REGEXP.PASSWORD.test(password)
}

// 验证身份证号
export function validateIdCard(idCard: string): boolean {
  return REGEXP.ID_CARD.test(idCard)
}

// 验证URL
export function validateUrl(url: string): boolean {
  return REGEXP.URL.test(url)
}

// 验证中文
export function validateChinese(text: string): boolean {
  return REGEXP.CHINESE.test(text)
}

// 验证数字
export function validateNumber(num: string): boolean {
  return REGEXP.NUMBER.test(num)
}

// 验证金额
export function validateAmount(amount: string): boolean {
  return REGEXP.AMOUNT.test(amount)
}

// 验证是否为空
export function validateEmpty(value: any): boolean {
  if (value === null || value === undefined) {
    return true
  }
  if (typeof value === 'string' && value.trim() === '') {
    return true
  }
  if (Array.isArray(value) && value.length === 0) {
    return true
  }
  if (typeof value === 'object' && Object.keys(value).length === 0) {
    return true
  }
  return false
}

// 验证文件大小
export function validateFileSize(size: number, maxSize: number): boolean {
  return size <= maxSize
}

// 验证文件类型
export function validateFileType(file: File, types: string[]): boolean {
  return types.includes(file.type)
}
